#!/bin/sh
###
 # @Author: 火红色祥云 809880192@qq.com
 # @Date: 2023-12-26 17:11:34
 # @LastEditors: 火红色祥云 809880192@qq.com
 # @LastEditTime: 2023-12-26 17:11:47
 # @FilePath: /project_luckfox/shell/static_ip.sh
 # @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
### 


MAX_TRIES=10
TRIES=0


check_ip_address() {

  if ifconfig eth0 | grep -q "inet "; then
    return 0
  else
    return 1
  fi
}

static_ip()
{            
  
while [ $TRIES -lt $MAX_TRIES ]; do
  if check_ip_address; then
    echo "DHCP succeed!"
    ifconfig eth0 192.168.10.66 netmask 255.255.252.0   
    break
  else
    echo "wait DHCP IP..."
    TRIES=$((TRIES + 1))
    sleep 5 
  fi
done


if [ $TRIES -eq $MAX_TRIES ]; then
  echo "error"

fi
}
case $1 in
        start)
                echo "start"
                static_ip
                ;;
        stop)
                echo "stop"
                ;;
        *)
                exit 1
                ;;
esac
